package com.scuec.tourismwebsite.mapper;


import com.scuec.tourismwebsite.entity.FreeformPostComment;
import com.scuec.tourismwebsite.vo.Fcomment;
import org.apache.ibatis.annotations.*;
//
import java.util.List;

@Mapper
public interface FreeformPostCommentMapper {
    @Select("SELECT\n" +
            "    fpc.comment_id,\n" +
            "    fpc.comment_content,\n" +
            "    fpc.comment_date,\n" +
            "    u.nickname,u.user_id,u.avatar,u.ip_address\n" +
            "FROM\n" +
            "    freeform_post_comment fpc\n" +
            "        JOIN\n" +
            "    user u ON fpc.user_id = u.user_id\n" +
            "WHERE\n" +
            "    fpc.post_id = #{post_id}\n" +
            "ORDER BY\n" +
            "    fpc.comment_date DESC")
    List<Fcomment> findCommentById(Integer post_id);

    @Select("SELECT\n" +
            "    fpc.comment_id,\n" +
            "    fpc.comment_content,\n" +
            "    fpc.comment_date,\n" +
            "    u.nickname\n" +
            "FROM\n" +
            "    freeform_post_comment fpc\n" +
            "        JOIN\n" +
            "    user u ON fpc.user_id = u.user_id\n" +
            "WHERE\n" +
            "    fpc.post_id = #{post_id}\n" +
            "AND fpc.comment_content LIKE CONCAT('%', #{comment_content}, '%')\n" +
            "ORDER BY\n" +
            "    fpc.comment_date ASC")
    List<Fcomment> findCommentByIdCo(@Param("post_id") Integer post_id, @Param("comment_content") String comment_content);


    @Delete("DELETE FROM freeform_post_comment\n" +
            "WHERE comment_id = #{comment_id};")
    Integer deleteCommentById(Integer comment_id);

    @Insert("INSERT INTO freeform_post_comment (post_id,user_id,comment_content) VALUES (#{post_id},#{user_id},#{comment_content})")
    Integer insertComment(FreeformPostComment freeformPostComment);
}
